@echo off
setlocal enabledelayedexpansion
chcp 65001 > nul

echo ScanOS服务调试工具
echo ========================

set SERVICE_NAME=ScanOSService

:menu
echo.
echo 1. 检查服务状态
echo 2. 启动服务
echo 3. 停止服务
echo 4. 重新安装服务
echo 5. 查看服务日志
echo 6. 退出
echo.

choice /c 123456 /n /m "请选择操作: "
if errorlevel 6 exit /b
if errorlevel 5 goto view_log
if errorlevel 4 goto reinstall
if errorlevel 3 goto stop_service
if errorlevel 2 goto start_service
if errorlevel 1 goto check_status

:check_status
echo.
echo 服务状态:
sc query %SERVICE_NAME%
goto menu

:start_service
echo.
net start %SERVICE_NAME%
if !errorlevel! neq 0 (
    echo 服务启动失败，错误代码: !errorlevel!
)
goto menu

:stop_service
echo.
net stop %SERVICE_NAME%
if !errorlevel! neq 0 (
    echo 服务停止失败，错误代码: !errorlevel!
)
goto menu

:reinstall
echo.
echo 正在重新安装服务...
call "%~dp0install-service.bat"
goto menu

:view_log
echo.
if exist "%~dp0service-install.log" (
    echo === 服务安装日志 ===
    type "%~dp0service-install.log"
) else (
    echo 未找到服务安装日志
)

if exist "%~dp0Logs\service.log" (
    echo.
    echo === 服务运行日志 ===
    type "%~dp0Logs\service.log"
) else (
    echo 未找到服务运行日志
)
goto menu